package com.tongji.diy.utils
{
	import com.tongji.diy.model.RoomDataVO;
	
	import flash.geom.Point;
	
	import de.polygonal.ds.DListNode;

	public class OptimizationMath
	{
		public function OptimizationMath()
		{
		}
		
		public static function normalRandom():Number
		{
			var normalNumber:Number = 0;
			for(var i:int = 0 ; i < 12; ++i)
			{
				normalNumber += Math.random();
			}
			return normalNumber - 6;
		}
		
		//此函数将给定的随机数进行正态化处理，目标是用在家具在墙上进行随机处理时，可以近似正太地得到随机数
		public static function randomNumNormalHandler(randNum:Number/*, step:Number,maxStep:Number*/):Number
		{
			var normalNumber:Number = normalRandom()/12 ;
			randNum += normalNumber;

			if(randNum >= 1)
				return --randNum;
			else if(randNum < 0)
				return  randNum + 1;
			else
				return randNum;
		}
		
		
		public static function testnum(num:Number):Boolean
		{
			if(num>398 && num<400 || num > -400&& num < -398)
				return true;
			return false;
		}
		
		//返回值为真，说明家具在房间内部
		public static function furnitureInRoom(testFurnitureBox:Vector.<Point>, room:RoomDataVO):Boolean
		{
			var tempRoomVector:DListNode = room.roomPointList.head;
			
			for(var i:int = 0;i < testFurnitureBox.length; i++)
			{
				if(!PolygonMath.pointIsInPoly(tempRoomVector, testFurnitureBox[i].add(new Point(room.x, room.y))))
					return false;
			}
			return true
		}		
		public static function assert(e:Boolean, mess:String=null):void {
			if(true && !e) {
				if(mess) trace(mess);
				trace(new Error().getStackTrace());
			}     
		}         
	}
}